﻿#region [===== Using =====]
using System;
#endregion

namespace TPG.SharePoint.Workflow
{
    /// <summary>
    /// A control for modifying a workflow during workflow execution and 
    /// which can be hosted inside a page using the hosted control framework.
    /// </summary>
    public abstract class ModificationControl
        : WorkflowDataControl<ModificationData, ModificationMetaData>
    {
        #region [===== Protected methods =====]
        /// <summary>
        /// Gets the modification data as a typed object, automatically 
        /// deserializing the data from a string.
        /// </summary>
        /// <typeparam name="TData">The Type of data to use.</typeparam>
        /// <returns>The typed data.</returns>
        protected TData GetDataAs<TData>()
            where TData : class
        {
            ModificationData data = GetData();
            return data.GetTypedData<TData>(SerializationMode);
        }
        /// <summary>
        /// Saves the modification data as a typed object, automatically
        /// serializing the data to a string.
        /// </summary>
        /// <typeparam name="TData">The Type of data to use.</typeparam>
        /// <param name="data">The typed object</param>
        /// <returns>A <see cref="ModificationData" /> object containing the 
        /// data in serialized form.</returns>
        protected ModificationData SaveDataAs<TData>(TData data)
            where TData : class
        {
            return ModificationData.CreateUsingTypedData<TData>(data, SerializationMode);
        }
        #endregion
    }
}
